package com.zzw.zim.system.controller;

import com.zzw.zim.common.utils.Result;
import com.zzw.zim.security.utils.TokenUtils;
import com.zzw.zim.system.dto.SysAccountLoginDTO;
import com.zzw.zim.system.service.SysAuthService;
import com.zzw.zim.system.vo.SysTokenVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * zzw-bridge-system（系统管理）
 *
 * @author XiaoJie
 * @date 2025/5/11 22:51
 */
@Tag(name = "系统管理")
@RestController
@RequestMapping("system/auth")
@Slf4j
public class SystemController {
    @Resource
    private SysAuthService sysAuthService;

    @PostMapping("login")
    @Operation(summary = "系统登录")
    public Result<SysTokenVO> login (@RequestBody SysAccountLoginDTO login) {
        log.info("用户登录------>：{}",login);
        SysTokenVO token = sysAuthService.loginByAccount(login);
        return Result.ok(token);
	}

    @PostMapping("logout")
    @Operation(summary = "退出")
    public Result<String> logout (HttpServletRequest request) {
        sysAuthService.logout(TokenUtils.getAccessToken(request));
        return Result.ok();
    }

}
